package com.cgbl.service.adapter

import android.view.View
import android.widget.ImageView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.cgbl.service.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.robot.base.configs.AppConstants
import com.robot.base.util.arouter.ARouterUtil

class AddTeamTagAdapter(var checkEnable: Boolean = true) :
    BaseQuickAdapter<String, BaseViewHolder>(R.layout.app_item_add_team) {


    override fun convert(holder: BaseViewHolder, item: String) {

        val addTeaMemberAdapter = AddTeamMemberAdapter(checkEnable)
        val checkView = holder.getView<ImageView>(R.id.iv_check)
        checkView.visibility = if (checkEnable) View.VISIBLE else View.GONE
        val recyclerView: RecyclerView = holder.getView(R.id.recyclerView)
        recyclerView.apply {
            layoutManager = LinearLayoutManager(context)
            adapter = addTeaMemberAdapter
        }
        addTeaMemberAdapter.setCheckChange {
            val childSelectPos = addTeaMemberAdapter.selectPos
            checkView.isSelected = childSelectPos.size == addTeaMemberAdapter.data.size
        }
        addTeaMemberAdapter.setOnItemClickListener { adapter, view, position ->
            ARouterUtil.goToActivity(
                AppConstants.Router.Project.A_PERSONAL_PROFILE
            )
        }
        checkView.setOnClickListener {
            checkView.isSelected = !checkView.isSelected
            if (checkView.isSelected) {
                addTeaMemberAdapter.allCheck()
            } else {
                addTeaMemberAdapter.cancelAllCheck()
            }
        }
    }

}